home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / SOURCES / MESSAGE.C < prev    next >
C/C++ Source or Header  |  1980-01-03  |  3KB  |  112 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Message class implementation.
  25.  */
  26.  
  27. #include <InterViews/message.h>
  28. #include <InterViews/font.h>
  29. #include <InterViews/painter.h>
  30. #include <InterViews/shape.h>
  31. #include <stdlib.h>
  32.  
  33. Message::Message(const char* msg, Alignment al, int pad, int hstr, int vstr) {
  34.     Init(msg, al, pad, hstr, vstr);
  35. }
  36.  
  37. Message::Message(
  38.     const char* name,
  39.     const char* msg, Alignment al, int pad, int hstr, int vstr
  40. ) : (name) {
  41.     Init(msg, al, pad, hstr, vstr);
  42. }
  43.  
  44. void Message::Init (const char* t, Alignment a, int p, int hstr, int vstr) {
  45.     SetClassName("Message");
  46.     text = t;
  47.     alignment = a;
  48.     pad = p;
  49.     shape->hstretch = hstr;
  50.     shape->vstretch = vstr;
  51.     highlighted = false;
  52. }
  53.  
  54. void Message::Reconfig () {
  55.     const char* a = GetAttribute("text");
  56.     if (a != nil) {
  57.     text = a;
  58.     }
  59.     a = GetAttribute("padding");
  60.     if (a != nil) {
  61.     pad = atoi(a);
  62.     }
  63.     Font* f = output->GetFont();
  64.     shape->width = pad + f->Width(text) + pad;
  65.     shape->height = pad + f->Height() + pad;
  66.     shape->hshrink = pad + pad;
  67.     shape->vshrink = pad + pad;
  68. }
  69.  
  70. void Message::Realign (Alignment a) {
  71.     alignment = a;
  72.     Draw();
  73. }
  74.  
  75. void Message::Redraw (Coord l, Coord b, Coord r, Coord t) {
  76. #ifndef _3D
  77.     Coord x = 0, y = 0;
  78.     Align(alignment, shape->width, shape->height, x, y);
  79.     output->Clip(canvas, l, b, r, t);
  80.     if (highlighted) {
  81.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  82.     }
  83.     output->ClearRect(canvas, l, b, r, t);
  84.     output->Text(canvas, text, x + pad, y + pad);
  85.     if (highlighted) {
  86.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  87.     }
  88.     output->NoClip();
  89. #endif
  90. #ifdef _3D
  91.     Coord x = 0, y = 0;
  92.     Align(alignment, shape->width, shape->height, x, y);
  93.     output->Clip(canvas, l, b, r, t);
  94.     if (highlighted) {
  95.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  96.     }
  97.     output->ClearRect(canvas, l, b, r, t);
  98.     output->Text(canvas, text, x + pad, y + pad);
  99.     if (highlighted) {
  100.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  101.     }
  102.     output->NoClip();
  103. #endif
  104. }
  105.  
  106. void Message::Highlight (boolean b) {
  107.     if (highlighted != b) {
  108.     highlighted = b;
  109.     Draw();
  110.     }
  111. }
  112.